//
//  secureXJViewController.m
//  Qihuo
//
//  Created by Vencoo on 13-10-31.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//

#import "ASIFormDataRequest.h"
#import "JSON.h"
#import "secureXJViewController.h"
#import "UIButton+MyButton.h"
#import "XunJianViewController.h"
#import "FireControlViewController.h"
#import "TimeClockViewController.h"
#import "EmergencyViewController.h"
#import "HighQuViewController.h"
#import "MieHuoQiViewController.h"
#import "CCTVViewController.h"
#import "CarPortViewController.h"

@interface secureXJViewController ()
{
    ASIFormDataRequest *loginRequest;
    UIImageView *blackView;
    UIImageView *miehuoBlackView;
}
@end

@implementation secureXJViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    [Appinfomation shareIstance].strongXunJianCount = 10247;

    self.title = @"保安部巡检";
    NSArray *array = @[@"高区+外围巡检",@"低区+外围巡检",@"车库管理检查",@"灭火器与消火栓检查",@"C C T V监控",@"消防系统联通测试与设备检查",@"突发事件记录",@"查看巡检时刻表"];
    [self addArray:array];
    [self addBlackView];
    [self addMieHuoBlackView];
    //    NSURL *loginUrl = [NSURL URLWithString:getFloor];
    //
    //    loginRequest = [[ASIFormDataRequest alloc] initWithURL:loginUrl];
    //    [loginRequest setPostValue:nil forKey:nil];
    //    [loginRequest startSynchronous];
    //
    //    NSString *response = [loginRequest responseString];
    //    NSLog(@"response:%@",[response JSONValue]);
    //        NSDictionary *responseDic = [response JSONValue];
    //        _DataDic = [responseDic objectForKey:@"data"];
    //        NSLog(@"%@",_DataDic);
    self.openFrid = YES;
    
    
}

- (void)addMieHuoBlackView
{
    UIImage *blackImage = [UIImage imageNamed:@"黑底1"];
    miehuoBlackView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, scrennWidth, screenHeight)];
    miehuoBlackView.image = blackImage;
    miehuoBlackView.userInteractionEnabled = YES;
    [self.view addSubview:miehuoBlackView];
    UIImage *whiteImage = [UIImage imageNamed:@"小白白白底"];
    UIImageView *whiteView = [[UIImageView alloc]initWithImage:whiteImage];
    whiteView.frame = CGRectMake((scrennWidth - whiteImage.size.width)/2, (screenHeight - whiteImage.size.height)/2, whiteImage.size.width, whiteImage.size.height);
    [whiteView setUserInteractionEnabled:YES];
    [miehuoBlackView addSubview:whiteView];
    
    UILabel *ziliaokuLB = [UILabel new];
    ziliaokuLB.text = @"灭火器与消火栓检查";
    ziliaokuLB.font = [UIFont systemFontOfSize:36];
    CGSize size = [ziliaokuLB.text sizeWithFont:ziliaokuLB.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
    ziliaokuLB.frame = CGRectMake((whiteImage.size.width - size.width)/2, 75, size.width, size.height);
    [whiteView addSubview:ziliaokuLB];
    
    UIImage *btnImage = [UIImage imageNamed:@"资料库按钮"];
    UIImage *closeImage = [UIImage imageNamed:@"删除"];
    UIButton *clsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [clsBtn setImage:closeImage forState:UIControlStateNormal];
    clsBtn.frame = CGRectMake(whiteImage.size.width - closeImage.size.width - 15, 15, closeImage.size.width, closeImage.size.height);
    [clsBtn addTarget:self action:@selector(closeV) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:clsBtn];
    
    for (int i = 0 ; i < 2; i ++)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.frame = CGRectMake((whiteImage.size.width - btnImage.size.width*2)/3*(i+1)+(btnImage.size.width)*i, (whiteImage.size.height - ziliaokuLB.frame.size.height - ziliaokuLB.frame.origin.y)/2, btnImage.size.width, btnImage.size.height);
        btn.tag = i;
        UILabel *btnLb = [UILabel new];
        btnLb.font = [UIFont systemFontOfSize:36];
        if (btn.tag == 1) {
            btnLb.text = @"高区";
            size = [@"啊啊啊啊啊啊" sizeWithFont:btnLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        }else{
            btnLb.text = @"低区";
            size = [@"啊啊啊啊啊" sizeWithFont:btnLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        }
        [btnLb setNumberOfLines:0];
        [btnLb setTextAlignment:1];
        btnLb.backgroundColor = [UIColor clearColor];
        btnLb.frame = CGRectMake((btnImage.size.width - size.width)/2, (btnImage.size.height - size.height*2)/2, size.width, size.height*2);
        
        btnLb.textColor = [UIColor whiteColor];
        [btn addSubview:btnLb];
        [btn setBackgroundColor:[UIColor clearColor]];
        [btn setBackgroundImage:btnImage forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(miehuoPress:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView addSubview:btn];
    }
    miehuoBlackView.hidden = YES;
}

- (void)addBlackView
{
    
    UIImage *blackImage = [UIImage imageNamed:@"黑底1"];
    blackView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, scrennWidth, screenHeight)];
    blackView.image = blackImage;
    blackView.userInteractionEnabled = YES;
    [self.view addSubview:blackView];
    UIImage *whiteImage = [UIImage imageNamed:@"小白白白底"];
    UIImageView *whiteView = [[UIImageView alloc]initWithImage:whiteImage];
    whiteView.frame = CGRectMake((scrennWidth - whiteImage.size.width)/2, (screenHeight - whiteImage.size.height)/2, whiteImage.size.width, whiteImage.size.height);
    [whiteView setUserInteractionEnabled:YES];
    [blackView addSubview:whiteView];
    
    UILabel *ziliaokuLB = [UILabel new];
    ziliaokuLB.text = @"巡检时刻表";
    ziliaokuLB.font = [UIFont systemFontOfSize:36];
    CGSize size = [ziliaokuLB.text sizeWithFont:ziliaokuLB.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
    ziliaokuLB.frame = CGRectMake((whiteImage.size.width - size.width)/2, 75, size.width, size.height);
    [whiteView addSubview:ziliaokuLB];
    
    UIImage *btnImage = [UIImage imageNamed:@"资料库按钮"];
    UIImage *closeImage = [UIImage imageNamed:@"删除"];
    UIButton *clsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [clsBtn setImage:closeImage forState:UIControlStateNormal];
    clsBtn.frame = CGRectMake(whiteImage.size.width - closeImage.size.width - 15, 15, closeImage.size.width, closeImage.size.height);
    [clsBtn addTarget:self action:@selector(closeV) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:clsBtn];
    
    for (int i = 0 ; i < 2; i ++)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.frame = CGRectMake((whiteImage.size.width - btnImage.size.width*2)/3*(i+1)+(btnImage.size.width)*i, (whiteImage.size.height - ziliaokuLB.frame.size.height - ziliaokuLB.frame.origin.y)/2, btnImage.size.width, btnImage.size.height);
        btn.tag = i;
        UILabel *btnLb = [UILabel new];
        btnLb.font = [UIFont systemFontOfSize:36];
        if (btn.tag == 1) {
            btnLb.text = @"非正常开放日时刻表";
            size = [@"啊啊啊啊啊啊" sizeWithFont:btnLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        }else{
            btnLb.text = @"正常开放日时刻表";
            size = [@"啊啊啊啊啊" sizeWithFont:btnLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        }
        [btnLb setNumberOfLines:0];
        [btnLb setTextAlignment:1];
        btnLb.backgroundColor = [UIColor clearColor];
        btnLb.frame = CGRectMake((btnImage.size.width - size.width)/2, (btnImage.size.height - size.height*2)/2, size.width, size.height*2);

        btnLb.textColor = [UIColor whiteColor];
        [btn addSubview:btnLb];
        [btn setBackgroundColor:[UIColor clearColor]];
        [btn setBackgroundImage:btnImage forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(material:) forControlEvents:UIControlEventTouchUpInside];
        [whiteView addSubview:btn];
    }
    blackView.hidden = YES;

}

- (void)miehuoPress:(UIButton *)sender
{
    [Appinfomation shareIstance].miehuoQuFlag = sender.tag;
    MieHuoQiViewController *mxVC =[[MieHuoQiViewController alloc]init];
    [self.navigationController pushViewController:mxVC animated:YES];
    miehuoBlackView.hidden = YES;
}

- (void)material:(UIButton *)sender
{
    [Appinfomation shareIstance].strongXunJianCount = sender.tag;
    TimeClockViewController *clockV = [TimeClockViewController new];
    [self.navigationController pushViewController:clockV animated:YES];
    blackView.hidden = YES;
}
- (void)closeV
{
    miehuoBlackView.hidden = 1;
    blackView.hidden = 1;
}
- (void)clicked:(UIButton*)btn
{
    self.HighQu = btn.tag;
    _openFrid = 1;
    [Appinfomation shareIstance].strongXunJianCount = btn.tag;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//    XunJianViewController *xunjianV = [XunJianViewController new];
//    xunjianV.secureDelegate = self;
    switch (btn.tag) {
        case 0:
        {
            HighQuViewController *highQu = [HighQuViewController new];
            highQu.delegate = self;
            highQu.secureDelegate = self;
            [self.navigationController pushViewController:highQu animated:YES];
        }
            break;
        case 1:
        {
            HighQuViewController *lowerQuV = [HighQuViewController new];
            lowerQuV.delegate = self;
            lowerQuV.secureDelegate = self;
            [self.navigationController pushViewController:lowerQuV animated:YES];
        }
            break;
        case 2:
        {//
            _openFrid = 0;
            CarPortViewController *car =[[CarPortViewController alloc]init];
            car.secureDelegate = self;
            
            [self.navigationController pushViewController:car animated:YES];
        }
            break;
        case 3:
        {//灭火器
            miehuoBlackView.hidden = NO;
            //                MieHuoQiViewController *mxVC =[[MieHuoQiViewController alloc]init];
            //                [self.navigationController pushViewController:mxVC animated:YES];
        }
            break;
        case 4:
        {//cctv
            _openFrid = 0;
            CCTVViewController  *cctv =[[CCTVViewController alloc]init];
            cctv.secureDelegate = self;
            [self.navigationController pushViewController:cctv animated:YES];
        }
            break;
        case 5:
        {
            _openFrid = 0;
            FireControlViewController *fireV = [FireControlViewController new];
            fireV.secureDelegate = self;
            [self.navigationController pushViewController:fireV animated:YES];
        }
            break;
        case 6:
        {
            EmergencyViewController *emergency = [EmergencyViewController new];
            [self.navigationController pushViewController:emergency animated:YES];
        }
            break;
        case 7:
        {
            blackView.hidden = NO;
        }
            break;
        case 8:
        {
            [self.navigationController popViewControllerAnimated:YES];
        }
            break;

        default:
            break;
    }
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
